package pictionary2;

import java.awt.Point;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPanel;

public class PaintPanel extends JPanel{
   private int pointCount = 0; 
   private Point points[] = new Point[ 1000000 ];

   public PaintPanel(final MSN m){
      addMouseMotionListener(
         new MouseMotionAdapter(){
            @Override
            public void mouseDragged( MouseEvent event ){
               if ( getPointCount() < getPoints().length ){
                    getPoints()[ getPointCount() ] = event.getPoint();
                    setPointCount(getPointCount() + 1);
                    repaint();
                    try {
                        //System.out.println("se crean los hilos para mandar el pain");
                        //new Thread(new Escritor(m.getEe().getS(), m, 1)).start();
                    } catch (Exception ex) {
                        System.out.println(ex.getMessage());
                    }
               }
            }
         } 
      ); 
   }

   public void paintComponent( Graphics g ){
      super.paintComponent( g );
      for ( int i = 0; i < getPointCount(); i++ )
         g.fillOval( getPoints()[ i ].x, getPoints()[ i ].y, 15, 15 );
   }

    public int getPointCount() {
        return pointCount;
    }

    public void setPointCount(int pointCount) {
        this.pointCount = pointCount;
    }

    public Point[] getPoints() {
        return points;
    }

    public void setPoints(Point[] points) {
        this.points = points;
    }
}